%w{rubygems test/unit pathname shoulda matchy mocha fakeweb redgreen }.each{|lib| require lib}

FakeWeb.allow_net_connect=false;

dir =(Pathname(__FILE__).dirname + '../../lib/core').expand_path
require dir + 'twilolia'

class Test::Unit::TestCase
end

def fixture_file_path(filename)
  File.expand_path(File.dirname(__FILE__)+'/../fixtures/'+filename)
end

def fixture_file_content(filename)
  return '' if filename ==''
  file_path= fixture_file_path(filename)
  File.read(file_path)
end

def twitter_url(url)
  url=~ /^http/?url:"http://api.twitter.com#{url}"
end

# mock request and response
def stub_get(url,filename,status =nil)
  options ={:body => fixture_file_content(filename)}
  options.merge!({:status => status}) unless status.nil?
  mock_uri(url,options)
end

def stub_post(url,filename)
  mock_uri(url,{:body => fixture_file_content(filename)},:post)
end

def stub_put(url,filename)
  mock_uri(url,{:body => fixture_file_content(filename)},:put)
end

def stub_delete(url,filename)
  mock_uri(url,{:body => fixture_file_content(filename)},:delete)
end

private

def mock_uri(url,content,method = :get)
  FakeWeb.register_uri(method,twitter_url(url),content)
end

